package com.zp.business.controller.diagnosis;


import com.zp.business.api.diagnosis.ClinicRecordBo;
import com.zp.business.api.diagnosis.ClinicRecordVo;
import com.zp.business.service.diagnosis.IClinicRecordService;
import com.zp.common.core.controller.BaseController;
import com.zp.common.core.entity.R;
import com.zp.common.core.validate.AddGroup;
import com.zp.common.core.validate.EditGroup;
import com.zp.common.excel.utils.ExcelUtil;
import com.zp.common.log.annotation.Log;
import com.zp.common.log.enums.BusinessType;
import com.zp.common.myBatis.core.page.PageQuery;
import com.zp.common.myBatis.core.page.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 患者病历表控制器
 * 前端访问路由地址为:/business/clinicRecord
 *
 * @author zhang peng
 * @ date 2024-01-01
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/clinicRecord")
public class ClinicRecordController extends BaseController {

    private final IClinicRecordService iClinicRecordService;

    /**
     * 查询患者病历表列表 (分页)
     */
//    @SaCheckPermission("business:clinicRecord:list")
    @GetMapping("/selectPage")
    public TableDataInfo<ClinicRecordVo> selectPage (ClinicRecordBo bo, PageQuery pageQuery) {
        return iClinicRecordService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询患者病历表列表 (不分页)
     */
//    @SaCheckPermission("business:clinicRecord:list")
    @GetMapping("/list")
    public R<List<ClinicRecordVo>> list (ClinicRecordBo bo) {
        List<ClinicRecordVo> list = iClinicRecordService.queryList(bo);
        return R.ok(list);
    }

    /**
     * 导出患者病历表列表
     */
//    @SaCheckPermission("business:clinicRecord:export")
    @Log(title = "患者病历表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export (ClinicRecordBo bo, HttpServletResponse response) {
        List<ClinicRecordVo> list = iClinicRecordService.queryList(bo);
        ExcelUtil.exportExcel(list, "患者病历表", ClinicRecordVo.class, response);
    }

    /**
     * 获取患者病历表详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("business:clinicRecord:list")
    @GetMapping("/{id}")
    public R<ClinicRecordVo> getInfo (@NotNull(message = "主键不能为空") @PathVariable String id) {
        return R.ok(iClinicRecordService.queryById(id));
    }

    /**
     * 新增患者病历表
     */
//    @SaCheckPermission("business:clinicRecord:add")
    @Log(title = "患者病历表", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add (@Validated(AddGroup.class) @RequestBody ClinicRecordBo bo) {
        return toAjax(iClinicRecordService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改患者病历表
     */
//    @SaCheckPermission("business:clinicRecord:edit")
    @Log(title = "患者病历表", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit (@Validated(EditGroup.class) @RequestBody ClinicRecordBo bo) {
        return toAjax(iClinicRecordService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除患者病历表
     *
     * @param ids 主键串
     */
//    @SaCheckPermission("business:clinicRecord:remove")
    @Log(title = "患者病历表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove (@NotEmpty(message = "主键不能为空") @PathVariable String[] ids) {
        return toAjax(iClinicRecordService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
